package com.example.qxfw.common.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.dto.InPolygonDto;
import com.example.qxfw.common.entity.qx.SmallScaleStation;
import com.example.qxfw.common.entity.qx.TownshipStation;
import com.example.qxfw.common.entity.xt.CollectConfig;
import com.example.qxfw.common.entity.xt.GridAddName;
import com.example.qxfw.common.entity.xt.SysConfig;
import com.example.qxfw.common.entity.xt.YbzzConfig;
import com.example.qxfw.common.service.CollectConfigService;
import com.example.qxfw.common.service.GridAddNameService;
import com.example.qxfw.common.util.DmgisUtils;
import com.example.qxfw.rcyw.pojo.JobMake;
import com.example.qxfw.rcyw.service.JobMakeService;
import com.example.qxfw.rcyw.service.SmallScaleStationService;
import com.example.qxfw.ybzz.service.SysConfigService;
import com.example.qxfw.ybzz.service.TownshipStationService;
import com.example.qxfw.ybzz.service.YbzzConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "公共接口")
@RestController
@CrossOrigin
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private SysConfigService sysConfigService;

    @Autowired
    private CollectConfigService collectConfigService;

    @Autowired
    private TownshipStationService townshipStationService;

    @Autowired
    private SmallScaleStationService smallScaleStationService;

    @Autowired
    private JobMakeService jobMakeService;

    @Autowired
    private YbzzConfigService ybzzConfigService;

    @Autowired
    private GridAddNameService gridAddNameService;

    @ApiOperation("/获取配置")
    @GetMapping("/getSysConfig")
    private SysResult getSysConfig(){
        List<SysConfig> list = sysConfigService.getList1();
        return SysResult.success(list);
    }

    @ApiOperation("获取服务用语")
    @GetMapping("/getServiceLanguage")
    public SysResult getServiceLanguage(){
        List<SysConfig> serviceLanguage = sysConfigService.getServiceLanguage();
        return SysResult.success(serviceLanguage);
    }

    @ApiOperation("获取采集配置文件")
    @GetMapping("/getCollectConfig")
    public SysResult getCollectConfig(){
        List<CollectConfig> list = collectConfigService.getList();
        return SysResult.success(list);
    }

    @ApiOperation("获取乡镇站点数据")
    @GetMapping("/getTownshipStation")
    public SysResult getTownshipStation(String city){
        List<TownshipStation> list = townshipStationService.getList2(city);
        return SysResult.success(list);
    }

    @ApiOperation("获取区域自动站站点信息")
    @GetMapping("/getSmallScaleStation")
    public SysResult getSmallScaleStation(String city){
        List<SmallScaleStation> list = smallScaleStationService.getList6(city);
        return SysResult.success(list);
    }

    @ApiOperation("获取业务制作信息")
    @GetMapping("/getJobMake")
    public SysResult getJobMake(){
        List<JobMake> list = jobMakeService.getList1();
        return SysResult.success(list);
    }

    @ApiOperation("获取网格信息")
    @GetMapping("/getYbzzConfig")
    public SysResult getYbzzConfig(){
        List<YbzzConfig> list = ybzzConfigService.getList();
        return SysResult.success(list);
    }

    @ApiOperation("获取格点别名")
    @GetMapping("/getGridAddName")
    public SysResult getGridAddName(){
        List<GridAddName> list = gridAddNameService.getList();
        return SysResult.success(list);
    }

    @ApiOperation("更新配置")
    @PostMapping("/updateSysConfig")
    public SysResult updateSysConfig(SysConfig sysConfig){
        Integer rows = sysConfigService.updateByParamName(sysConfig);
        return SysResult.success(rows);
    }

    @ApiOperation("获取文档产品的期数")
    @GetMapping("/getSysConfig1")
    public SysResult getSysConfig1(String paramName){
        List<SysConfig> list = sysConfigService.getList2("产品期数",paramName);
        return SysResult.success(list);
    }

    @ApiOperation("更新文档产品的期数")
    @PostMapping("/updateSysConfig1")
    public SysResult updateSysConfig2(SysConfig sysConfig){
        Integer rows = sysConfigService.update(sysConfig);
        return SysResult.success(rows);
    }

    @ApiOperation("保存文档产品期数")
    @PostMapping("/saveSysConfig")
    public SysResult saveSysConfig(SysConfig sysConfig){
        Integer rows = sysConfigService.save(sysConfig);
        return SysResult.success(rows);
    }

    @ApiOperation("判断点是否在多边形内")
    @PostMapping("/inPolygon")
    public SysResult inPolygon(@RequestBody InPolygonDto inPolygonDto){
        Boolean inPolygon = DmgisUtils.isScope(inPolygonDto.getMapPoint(),inPolygonDto.getPolygon());
        return SysResult.success(inPolygon);
    }

}
